package com.aWei.springbootinit.dataSource;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.aWei.springbootinit.model.dto.post.PostQueryRequest;
import com.aWei.springbootinit.model.vo.PostVO;
import com.aWei.springbootinit.service.PostService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 帖子服务实现
 *
 阿维
 */
@Service
@Slf4j
public class PostDataSource implements DataSource<PostVO> {
        @Resource
        private PostService postService;

        @Override
        public Page<PostVO> doSearch(String searchText, long pageNum, long pageSize) {
                PostQueryRequest postQueryRequest = new PostQueryRequest();
                postQueryRequest.setSearchText(searchText);
                postQueryRequest.setPageSize(pageSize);
                postQueryRequest.setCurrent(pageNum);
                //获取当前线程的对象
                ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
                HttpServletRequest request = servletRequestAttributes.getRequest();
                Page<PostVO> postVOPage = postService.listPostVOByPage(postQueryRequest, request);
                return postVOPage;
        }
}




